
#pragma once

#include "ITask.h"
#include "LuaEng.h"

#include "EventSystem.h"
#include "Unidad.h"

#include <string>
#include <boost/weak_ptr.hpp>

#include "ManagerDeObjetos.h"

//! Task which periodically recovers the specified shield and energy percent of a Unit.
//!
class TareaRegenerar : public ITask
{

	boost::weak_ptr<Unidad> mUnit;
	float mEnergyRegenPercent;
	float mShieldRegenPercent;

public:

	//! Constructs a TaskRegen
	//!
	TareaRegenerar(boost::weak_ptr<Unidad> & uni, float energyRegenPercent, float shieldRegenPercent)
		: mUnit(uni), mEnergyRegenPercent(energyRegenPercent), mShieldRegenPercent(
		shieldRegenPercent)
	{
	}

	//! Executes the event
	//!
	virtual bool Execute()
	{
		Unidad * uni = mUnit.lock().get();
		if(uni)
		{
			TipoUnidad const & type = ManagerDeObjetos::Get()->GetTipoUnidad(uni->GetNombreTipo());
			float shieldRegen = type.escudo * mShieldRegenPercent;
			float energyRegen = type.energia * mEnergyRegenPercent;
			uni->SetEnergia(uni->GetEnergia() + energyRegen);
			uni->SetEscudo(uni->GetEscudo() + shieldRegen);
			if(uni->GetEnergia() > type.energia)
				uni->SetEnergia(type.energia);
			if(uni->GetEscudo() > type.escudo)
				uni->SetEscudo(type.escudo);
		}
		else
			return false;
	}



};